package cn.joeg.app.web.items.user;


import cn.joeg.app.web.db.user.UserService;
import cn.joeg.app.web.util.Const;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class UserHelper {


    static String tempString(UserService.UserVO userVO, int ver) {
        //存放不在UserVO中的对象，最后与UserVO 对象做合并
        Map<String, Object> tmpMap = new HashMap<>();

        if (ver >= 10) {
            //girl's side
            userVO.setCompanylevel(userVO.getGirlcompanylevel());
            userVO.setCompanyexp(userVO.getGirlcompanyexp());
            if (userVO.getCompanylevel() == 0) {
                tmpMap.put("companytargetexp", Const.user_lev_exp[userVO.getGirlcompanylevel()]);
            } else {
                tmpMap.put("companytargetexp", Const.user_lev_exp[userVO.getGirlcompanylevel() - 1]);
            }
        } else {
            //userVO.setCompanytargetexp(userVO.getCompanylevel());
            tmpMap.put("companytargetexp", Const.user_lev_exp[userVO.getCompanylevel() - 1]);
        }
        return "";
    }


    /**
     * 取最大等级公司
     *
     * @param list
     * @param serverid
     * @return
     */
    static UserService.UserVO getMaxLevelUser(List<UserService.UserVO> list, int serverid) {
        UserService.UserVO userMap = new UserService.UserVO();
        for (UserService.UserVO map : list) {
            // 取最大等级公司
            if (userMap.getCompanylevel() < map.getCompanylevel()) {
                userMap = map;
            }
            long userid = (long) map.getId();
            //TODO 祖传代码 服务器ID 亿位数
            if (serverid <= 20) {
                if (userid / 100000000 == serverid) {
                    userMap = map;
                    break;
                }
            } else {
                if (userid / 1000000 == serverid) {
                    userMap = map;
                    break;
                }
            }
        }
        return userMap;
    }


}
